package com.company.oa.hr.mapper.employee;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.company.oa.hr.entity.employee.Attendance;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Map;

/**
 * 考勤记录数据访问层
 */
@Mapper
public interface AttendanceMapper extends BaseMapper<Attendance> {
    
    /**
     * 分页查询考勤记录，并关联员工信息
     *
     * @param page 分页参数
     * @param attendance 查询条件
     * @return 考勤记录分页数据
     */
    @Select({
        "<script>",
        "SELECT",
        "    a.*,",
        "    e.name as employee_name,",
        "    e.employee_no",
        "FROM attendance a",
        "LEFT JOIN employee e ON a.employee_id = e.id",
        "<where>",
        "    <if test='attendance.employeeId != null'>",
        "        AND a.employee_id = #{attendance.employeeId}",
        "    </if>",
        "    <if test='attendance.attendanceDate != null'>",
        "        AND a.attendance_date = #{attendance.attendanceDate}",
        "    </if>",
        "    <if test='attendance.status != null'>",
        "        AND a.status = #{attendance.status}",
        "    </if>",
        "</where>",
        "ORDER BY a.attendance_date DESC",
        "</script>"
    })
    IPage<Map<String, Object>> selectAttendancePageWithEmployee(Page<?> page, @Param("attendance") Attendance attendance);
}